package map;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Test_2 {
    public static void main(String[] args) {
        String line = "Thinking in java! i love java";
        Map<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < line.length(); i++) {
            char c = line.charAt(i);
            if (map.containsKey(c)) {
                Integer sum = map.get(c);
                sum = sum + 1;
                map.put(c, sum);
            } else {
                map.put(c, 1);
            }
        }
        System.out.println(map);
        Set<Map.Entry<Character, Integer>> entries = map.entrySet();
        for (Map.Entry<Character,Integer> entry: entries){
            Character key = entry.getKey();
            Integer value = entry.getValue();
            System.out.println(key + ":" + value);
        }

        System.out.println("-------");
        map.forEach(
                (k,y) -> System.out.println(k + ";" + y)
        );

    }
}
